home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_ciel_client_tracking.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  7.0 KB  |  317 lines

  1. unit ntc_ciel_client_tracking;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Variants,
  30.     Classes,
  31.     Graphics,
  32.     Controls,
  33.     Forms,
  34.     Dialogs,
  35.     StdCtrls,
  36.     Buttons,
  37.     ExtCtrls,
  38.     inifiles,
  39.  
  40.     ntc_ciel_client_form;
  41.  
  42. const
  43.     default_deviation=0.1;
  44.     default_rate=60;
  45.     default_lunar_rate=57.9;
  46.  
  47. type
  48.     Tscope_tracking = class(tform)
  49.         tracking_panel: TPanel;
  50.         change_tracking_group: TGroupBox;
  51.         increase_tracking_button: TBitBtn;
  52.         preset_defaults_group: TGroupBox;
  53.         lunar_tracking_button: TBitBtn;
  54.         default_tracking_button: TBitBtn;
  55.         lunar_tracking_label: TLabel;
  56.         default_tracking_label: TLabel;
  57.         decrease_tracking_button: TBitBtn;
  58.         tracking_edit: TEdit;
  59.  
  60.         { form handling }
  61.         procedure FormCreate(
  62.             Sender: TObject);
  63.  
  64.         procedure form_close_query(
  65.                     Sender: TObject;
  66.             var CanClose: Boolean);
  67.  
  68.         { configuration }
  69.         procedure save_settings;
  70.  
  71.         procedure load_settings;
  72.  
  73.         procedure flip_buttons(
  74.             toggle:boolean);
  75.  
  76.         { events }
  77.         procedure FormShow(
  78.             Sender:TObject);
  79.  
  80.         procedure adjust;
  81.  
  82.         procedure check_activate(
  83.             Sender: TObject);
  84.  
  85.         procedure decrease_tracking_buttonClick(
  86.             Sender: TObject);
  87.  
  88.         procedure increase_tracking_buttonClick(
  89.             Sender: TObject);
  90.  
  91.         procedure lunar_tracking_buttonClick(
  92.             Sender: TObject);
  93.  
  94.         procedure default_tracking_buttonClick(
  95.             Sender: TObject);
  96.  
  97.         procedure tracking_editChange(
  98.             Sender: TObject);
  99.  
  100.     private
  101.         { Private declarations }
  102.         default_tracking_rate,
  103.         default_lunar_tracking_rate:double;
  104.         tracking_rate,
  105.         lunar_tracking_rate:double;
  106.         lunar_tracking:boolean;
  107.     public
  108.         { Public declarations }
  109.         can_track:boolean;
  110.         tracks_by:double;
  111.         { configuration }
  112.         dimensions:dimensions_record;
  113.  
  114.         { events }
  115.         procedure check_visible_and_show_hide(
  116.             sender:tobject);
  117.             
  118.         procedure hide_form;
  119.         procedure show_form;
  120.     end;
  121.  
  122. var
  123.     scope_tracking:Tscope_tracking;
  124.  
  125. implementation
  126.  
  127. uses
  128.     ntc_ciel_client_network;
  129.  
  130. {$R *.dfm}
  131.  
  132.     { -------------
  133.         form handling
  134.         ------------- }
  135.  
  136. procedure Tscope_tracking.FormCreate(Sender: TObject);
  137. begin
  138.     default_tracking_rate:=default_rate;
  139.     tracking_rate:=default_tracking_rate;
  140.     default_lunar_tracking_rate:=default_lunar_rate;
  141.     lunar_tracking_rate:=default_lunar_tracking_rate;
  142.     tracking_edit.text:=floattostr(tracking_rate);
  143.     lunar_tracking:=false;
  144.     can_track:=false;
  145.     tracks_by:=default_deviation;
  146.     flip_buttons(false);
  147.     load_settings;
  148.     visible:=false;
  149. end;
  150.  
  151. procedure tscope_tracking.form_close_query(
  152.             Sender: TObject;
  153.     var CanClose: Boolean);
  154. begin
  155.     visible:=false;
  156.     with dimensions do
  157.         begin
  158.             form_top:=top;
  159.             form_left:=left;
  160.         end;
  161.     if ciel_closing then
  162.         canclose:=true
  163.     else
  164.         canclose:=false;
  165. end;
  166.  
  167.     { ---------
  168.         utilities
  169.         --------- }
  170.  
  171. procedure Tscope_tracking.flip_buttons(
  172.     toggle:boolean);
  173. begin
  174.     change_tracking_group.enabled:=toggle;
  175.     preset_defaults_group.enabled:=toggle;
  176. end;
  177.  
  178.     { -------------
  179.         configuration
  180.         ------------- }
  181.  
  182. procedure tscope_tracking.load_settings;
  183. begin
  184.     ini_file:=tinifile.create(application_path+'ciel.ini');
  185.     with ini_file do
  186.         begin
  187.             tracks_by:=ReadFloat('tracking','tracks_by',default_deviation);
  188.             default_tracking_rate:=ReadFloat(
  189.                 'tracking','default_tracking_rate',default_rate);
  190.             default_lunar_tracking_rate:=readfloat(
  191.                 'tracking','default_lunar_tracking_rate',default_lunar_rate);
  192.             { form }
  193.             scope.get_dimensions(scope_tracking,@dimensions,'tracking',ini_file);
  194.             left:=dimensions.form_left;
  195.             top:=dimensions.form_top;
  196.             visible:=readbool('tracking','visible',false);
  197.         end;
  198.     ini_file.free;
  199. end;
  200.  
  201. procedure tscope_tracking.save_settings;
  202. begin
  203.     with ini_file do
  204.         begin
  205.             writefloat('tracking','default_tracking_rate',default_tracking_rate);
  206.             writefloat(
  207.                 'tracking','default_lunar_tracking_rate',default_lunar_tracking_rate);
  208.             writefloat('tracking','tracks_by',tracks_by);
  209.             { form }
  210.             scope.find_vdu(scope_tracking,@dimensions);
  211.             scope.write_dimensions(@dimensions,left,top,'tracking',ini_file);
  212.             writebool('tracking','visible',visible);
  213.         end;
  214. end;
  215.  
  216.     { ------
  217.         events
  218.         ------ }
  219.  
  220. procedure tscope_tracking.FormShow(
  221.     Sender:TObject);
  222. begin
  223.     with dimensions do
  224.         begin
  225.             top:=form_top;
  226.             left:=form_left;
  227.         end;
  228. end;
  229.  
  230. procedure tscope_tracking.adjust;
  231. begin
  232.     with dimensions do
  233.         begin
  234.             form_top:=trunc(form_top/last_screen_height*current_height);
  235.             form_left:=trunc(form_left/last_screen_width*current_width);
  236.         end;
  237.     if visible then
  238.         show;
  239. end;
  240.  
  241. procedure tscope_tracking.check_visible_and_show_hide(
  242.     sender:tobject);
  243. begin
  244.     if visible then
  245.         hide_form
  246.     else
  247.         show_form;
  248.     scope.show_hide(sender,visible);
  249. end;
  250.  
  251. procedure tscope_tracking.hide_form;
  252. begin
  253.     with dimensions do
  254.         begin
  255.             form_top:=top;
  256.             form_left:=left;
  257.         end;
  258.     Visible:=false;
  259.     formstyle:=fsnormal;
  260. end;
  261.  
  262. procedure tscope_tracking.show_form;
  263. begin
  264.     formstyle:=fsstayontop;
  265.     Visible:=true;
  266. end;
  267.  
  268. procedure Tscope_tracking.check_activate(
  269.     Sender: TObject);
  270. begin
  271.     scope.form_activate(scope_tracking,@dimensions);
  272. end;
  273.  
  274. procedure Tscope_tracking.decrease_tracking_buttonClick(
  275.     Sender: TObject);
  276. begin
  277.     if (scope_network.send_request_check('decrease_tracking')>=[exit_ok]) then
  278.         begin
  279.             tracking_rate:=tracking_rate-default_deviation;
  280.             tracking_edit.text:=floattostr(tracking_rate);
  281.         end;
  282. end;
  283.  
  284. procedure Tscope_tracking.increase_tracking_buttonClick(
  285.     Sender: TObject);
  286. begin
  287.     if (scope_network.send_request_check('increase_tracking')>=[exit_ok]) then
  288.         begin
  289.             tracking_rate:=tracking_rate+default_deviation;
  290.             tracking_edit.text:=floattostr(tracking_rate);
  291.         end;
  292. end;
  293.  
  294. procedure Tscope_tracking.lunar_tracking_buttonClick(
  295.     Sender: TObject);
  296. begin
  297.     scope_network.send_request_check('lunar_tracking');
  298.     tracking_rate:=default_lunar_tracking_rate;
  299.     tracking_edit.text:=floattostr(tracking_rate);
  300. end;
  301.  
  302. procedure Tscope_tracking.default_tracking_buttonClick(
  303.     Sender: TObject);
  304. begin
  305.     scope_network.send_request_check('default_tracking');
  306.     tracking_rate:=default_tracking_rate;
  307.     tracking_edit.text:=floattostr(tracking_rate);
  308. end;
  309.  
  310. procedure Tscope_tracking.tracking_editChange(
  311.     Sender: TObject);
  312. begin
  313.     tracking_edit.text:=floattostr(tracking_rate);
  314. end;
  315.  
  316. end.
  317.